/**
 * 基于XLSX的Excel数据导出组件
 * @author SPY
 * @date 2020/03/15
 */

import React, { Component } from 'react';
import { Table, Button, Card } from 'antd';
import ImportExcel from './components/ImportExcel';

const dataSource = [
    {
        key: '1',
        name: '胡彦斌',
        age: 32,
        address: '西湖区湖底公园1号',
    },
    {
        key: '2',
        name: '胡彦祖',
        age: 32,
        address: '西湖区湖底公园1号',
    },
];

const columns = [
    {
        title: '姓名',
        dataIndex: 'name',
        key: 'name',
    },
    {
        title: '年龄',
        dataIndex: 'age',
        key: 'age',
    },
    {
        title: '住址',
        dataIndex: 'address',
        key: 'address',
    },
];

class ExcelImportPage extends Component {

    handleImportFile = () => {
        ImportExcel([{ headers: columns, data: dataSource, sheetName: "员工基本信息" }], "员工基本信息表")
    }

    render() {
        return (
            <Card>
                <Button
                    type='primary'
                    icon='import'
                    style={{ marginBottom: '1%' }}
                    onClick={this.handleImportFile}
                >
                    导出excel文件
                </Button>
                <Table dataSource={dataSource} columns={columns} />
            </Card>
        );
    }
}

export default ExcelImportPage;
